package com.tf_cut.backend.platform.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.tf_cut.backend.common.pojo.Result;
import com.tf_cut.backend.platform.service.GrantDetailService;
import com.tf_cut.backend.platform.service.GrantService;
import com.tf_cut.backend.platform.vo.ListGrantDetailVo;
import com.tf_cut.backend.seller.service.SellerOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/backend/admin/platform/grantdetail")
public class GrantDetailController {
    @Autowired
    private GrantService grantService;
    @Autowired
    private GrantDetailService grantDetailService;
    @Autowired
    private SellerOrderService sellerOrderService;

    @PostMapping("/update")
    public String queryPlatformGrantList(@RequestBody String json) {
        log.info("grantdetail update receive data:{}",json);
        Result<String> result = Result.of("更新成功");;
        try {
            ListGrantDetailVo listGrantDetailVo = JSON.parseObject(json, ListGrantDetailVo.class);
            grantDetailService.updateGrantDetailBatch(listGrantDetailVo.getGrantDetailList());
        } catch (Exception e) {
            log.error("queryPlatformGrantList error:{}", e.getMessage(), e);
            result = Result.of("更新失败");
            result.setMsg(e.getMessage());
            result.setFlag(false);
        }
        return JSON.toJSONString(result, SerializerFeature.WriteDateUseDateFormat);
    }


}
